#include <stdio.h>
#include <string.h>

int dp[1001][1001];
char s1[1001], s2[1001];

int main()
{
    int i, j, len1, len2;
    while (1) 
    {
          if (scanf("%s%s", &s1, &s2) == EOF) break;
          len1 = strlen(s1);
          len2 = strlen(s2);
          memset(dp, 0, sizeof(dp));
          
          if (s1[0] == s2[0]) dp[0][0] = 1;
          else dp[0][0] = 0;
          
          for (i = 1; i < len2; ++i) 
          {
              if (s1[0] == s2[i]) dp[0][i] = 1;
              else dp[0][i] = dp[0][i-1];
          }
          for (i = 1; i < len1; ++i)
          {
             if (s2[0] == s1[i]) dp[i][0] = 1;
             else dp[i][0] = dp[i-1][0];
          }
          
          for (i = 1; i < len1; ++i)
              for (j = 1; j < len2; ++j)
              {
                  if (s1[i] == s2[j]) dp[i][j] = dp[i-1][j-1]+1;
                  else dp[i-1][j-1];
                  if (dp[i][j] < dp[i-1][j]) dp[i][j] = dp[i-1][j];
                  if (dp[i][j] < dp[i][j-1]) dp[i][j] = dp[i][j-1];
              }
          printf("%d\n", dp[len1-1][len2-1]);
    }
    
    
}
